<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@page import="com.google.appengine.api.users.UserService"%>
<%@page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@page import="com.google.appengine.api.users.User"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="kr.icg.mshtest2.PMF"%>
<%@page import="kr.icg.mshtest2.Mention"%>
<%@page import="java.util.List"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GOING 747</title>
<%
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null) {
%>
<script type="text/javascript">
var email = "<%= user.getEmail() %>";
var nickName = "<%= user.getNickname() %>";
var sign = "<form id='f'><input id='content' type='text' value='abcde'></input><input type='button' value='입력' onclick=\"requestHello('/icg_msh_test2');addMyMarker()\"></form><a href='<%= userService.createLogoutURL(request.getRequestURI()) %>'>sign out</a>";
</script>
<%
} else {
%>
<script type="text/javascript">
var email = "무명씨";
var nickName = "무명";
var sign = "<a href='<%= userService.createLoginURL(request.getRequestURI()) %>'>Sign in</a>";
</script>
<%
}
%>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

<script type="text/javascript" src="http://www.google.com/jsapi"></script>	
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>	

<script type="text/javascript" src="/inits/init.js"></script>
<script language=javascript>
//깔끔하게 한번만 
function addMyMarker()
{
    myMarker.setMap(null);
    myMarker = null;
	move();
}
function move()
{
	var bound = map.getBounds();
	//var a = document.getElementById("ne");
	//  alert("move2"+a.value);	
	//  a.value = bound.getNorthEast();
	//  alert("move2"+a.value);	
	  
	  var sw = bound.getSouthWest();
	  var ne = bound.getNorthEast();
	 
	  
	  
	    param = "s="+sw.lng()+"&n="+ne.lng()+"&e="+ne.lat()+"&w="+sw.lat();
	    URL = "/GetMention";
		 //alert(param);
		 //alert(URL);
	    xhr = getXMLHttpRequest();
	    xhr.open("POST", URL, true);
	    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
	    xhr.onreadystatechange = getMentionList;	
	    xhr.send(param);
	   
      	   
	    
}

function getMentionList()
{
	if (xhr.readyState == 4) 
	{
        if (xhr.status == 200) 
        {        	
            var str = xhr.responseText;
            if(str.length > 9)
            {
            	putMarker(str);    
            }

        <% 
            if (user == null) 
            {
        %>
        		//alert("nouser-mymark="+myMarker)
		      //내마커 삭제
        		if(myMarker)
        			myMarker.setMap(null);
        <%    
            }
            else
            {
        %>  	
		        if(!myMarker )
		        {
		        	noMyMarker();       
		        }
        <%
            }
        %>
            
        } else {
            alert("Fail : " + xhr.status);
        }
        
    }
}

function initialize() {
    var latlng = new google.maps.LatLng(33.499621, 126.531188);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeControl: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    google.maps.event.addListener(map, 'bounds_changed',function() 
  			{
  				//First div's update to show actual location details
    	  move(); 
  				google.maps.event.addListener(map, 'dragend',function() { move() });
  				//Map fully loaded, clear the listener
  				google.maps.event.clearListeners(map, 'bounds_changed');
  				//And add two new events, one will update the div's info when user ends dragging the map and the other when map's zoom changes
  				//google.maps.event.addListener(map, 'dragend',function() { actualizaUbicacion() });
  				google.maps.event.addListener(map, 'zoom_changed',function() { move() });
  			}
  		);
    
    
    


    

    

    var callToControlDiv = document.createElement('DIV');
    var callToControl = new CallToControl(callToControlDiv, map);

    callToControlDiv.index = 1;
    map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(callToControlDiv);
    
    var moveToControlDiv = document.createElement('DIV');
    var moveToControl = new MoveToControl(moveToControlDiv, map);
    
    moveToControlDiv.index = 1;
    map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(moveToControlDiv);
    
    var accountControlDiv = document.createElement('DIV');
    var accountControl = new AccountControl(accountControlDiv, map);
    
    accountControlDiv.index = 1;
    map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(accountControlDiv);
}

</script>
</head>
<body onload="initialize()" style="margin:0px">
<input type="hidden" id='ne' value = ''>
	<div id="map_canvas" style="width:100%; height:100%"></div>
	<div style="height:100px"></div>
</body>
</html>